<template>
  <div>
    <h1 id="myh1">浏览器事件</h1>
    <img @click="requestData" src="../assets/1614740577862.png" alt="">
    <img @click="requestData" src="../assets/baobeier.jpeg" alt="">
  </div>
</template>

<script>
  import {getUser} from "../api/users";

  export default {
    name: "Page",
    methods: {
      async requestData() {
        let res = await getUser();// promise
        // console.log(res)
      }
    },

    created() {

      setTimeout(() => {
        console.log(4);

        let result = new Promise((resolve, reject) => {
          resolve(5);
        });
        result.then(res => console.log(res));
      }, 0);
      let promise = new Promise((resolve, reject) => {
        console.log(1);
        setTimeout(() => {
          resolve(3);
        }, 0);
      });
      console.log(2);
      promise.then(res => console.log(res));
      // 宏任务
      // 微任务
      // 1 2 4 5 3

      // 1 2 3 4

      // 4213
      // 1234
      // 1324
      // 1243
      // 4231

    }
    /* created() {
       function fn() {
         this.a = 0;
         this.b = function () {
           console.log("-1-")
           window.alert(this.a)
         }
       }
       fn.prototype = {
         b: function () {
           console.log("-2-")
           this.a = 20;
           window.alert(this.a)
         },
         c: function () {
           this.a = 30;
           window.alert(this.a)
         }
       }
       var myFn = new fn()
       myFn.b();
       myFn.c();
       console.log(myFn)
     }*/
  }
</script>

<style scoped>

</style>
